package edu.auctionmart

import org.joda.time.DateTime
import org.quartz.*

import edu.auctionmart.jobs.AlertReminderJob;

class ScheduleAlertService {
	
	public static final String JOB_GROUP_NAME = "default";

	def quartzScheduler 
	
	def scheduleAlertJob(DateTime alertTime, String auctionName, String userName, AlertType alertType, Object service, Object queueService) {
		
		if (alertTime == null || auctionName == null || userName == null || alertType == null) { return } 
		
		String jobId = alertTime.toString().replace(".", "-") + "." + auctionName + "." + userName + "." + alertType.toString()
		JobDetail job = new JobDetail(jobId, JOB_GROUP_NAME, AlertReminderJob.class)

		JobDataMap map = job.getJobDataMap()
		map.put("service", service)
		map.put("queueService", queueService)
		Date date = alertTime.toDate()
		Trigger trigger = new SimpleTrigger(jobId, JOB_GROUP_NAME, date);
		quartzScheduler.scheduleJob(job, trigger)
		
	}
}
